package com.training.array;

public class BubbleSortDemo {
	public static void main(String args[]) {
		int[]a = {1,2,54541,3,13456,4,1231,4546,321};
		System.out.println("Before:");
		print(a);
		selectSort(a);
		System.out.println("\nAfter:");
		print(a);
	}
	public static void bubbleSort(int[] a) {
		for(int i = 0 ; i<a.length-1;i++) {
			for(int j = 0;j<a.length-i-1;j++) {
				if(a[j]>a[j+1]) {
					int temp = a[j];
					a[j] = a[j+1];
					a[j+1] = temp;
				}
			}
		}
	}
	public static void selectSort(int[] a) {
		int min = 0;
		int pos = 0;
		for (int i =0;i<a.length-1;i++) {
			min = a[i];
			pos = i;
			for(int j = i+1 ;j<a.length;j++) {
				if(min>a[j]) {
					min = a[j];
					pos = j;
				}
			}
			a[pos] = a[i];
			a[i] = min;
		}
	}
	public static void print(int[] a) {
		for(int t:a) {
			System.out.print(t+"\t");
		}
	}
}
